package com.yoomiito.app.ui.fragment.my;

import android.os.Bundle;

import com.yoomiito.app.Constant;
import com.yoomiito.app.adapter.my.MonthOrderAdapter;
import com.yoomiito.app.adapter.my.MyOrderAdapter;
import com.yoomiito.app.model.my.MyMonthOrderInfo;
import com.yoomiito.app.model.my.MyOrderBean;
import com.yoomiito.app.present.my.fragment.MyMonthOrderFmPresenter;
import com.yoomiito.app.ui.my.MyMonthOrderActivity;
import com.yoomiito.app.ui.my.MyTodayOrderActivity;

import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.net.ApiException;

/**
 * 月度详情界面
 */
@Deprecated
public class MyMonthOrderFragment extends MyOrderBaseFragment<MyMonthOrderFmPresenter> {

    public static final String MyMonthOrderFm = "MyMonthOrderFm";

//    @BindView(R.id.rv_order)
//    RecyclerView mRecyclerView;
    private MonthOrderAdapter mAdapter;
    private List<MyOrderBean> mList;
    private int month;

    @Override
    public MyMonthOrderFmPresenter newP() {
        return new MyMonthOrderFmPresenter();
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        if (getArguments() != null) {
            month = getArguments().getInt(Constant.KEY_MONTH, 0);
        }
        mList = new ArrayList<>();
        mAdapter = new MonthOrderAdapter();
        mRecyclerView.setAdapter(mAdapter);
        showLoading();
        getNewData();
    }

    @Override
    protected void getNewData() {
        getP().getData(currentPage, month);
    }

    @Override
    public String getEmptyContent() {
        return "未购买商品";
    }

    @Override
    public void handleError(ApiException e) {

    }

    public void setMonthOrderData(MyMonthOrderInfo data) {
        dismissLoading();
        ((MyMonthOrderActivity)context).moneyTv.setText(data.getMonthIncome());

        if (currentPage == 1) {
            if (data == null || data.getData() == null || data.getData().size()==0) {
                mStatusManager.showEmpty();
            }else {
                mAdapter.setNewData(data.getData());
                mSmartRefreshLayout.finishRefresh(true);
                mStatusManager.showContent();
            }
        }else {
            mSmartRefreshLayout.finishLoadMore(true);
            if (data.getData() == null || data.getData().size() == 0) {
                mSmartRefreshLayout.finishLoadMoreWithNoMoreData();
            } else {
                mAdapter.addData(data.getData());
            }
        }
    }

    public void finishReferesh() {
        mSmartRefreshLayout.finishRefresh(true);
        mSmartRefreshLayout.finishLoadMore(true);
    }
}
